package sg.edu.nus.iss.billing.gui;

//Tan Pic Cheng

import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import sg.edu.nus.iss.billing.gui.component.ValidateJTextField;
import sg.edu.nus.iss.billing.localization.MessageKeyManager;
import sg.edu.nus.iss.billing.validation.ValidationRule;

public class CustomerContactPanel extends JPanel {
	private String[] labelContent = {MessageKeyManager.getMessage("label.homeNo"), MessageKeyManager.getMessage("label.custMobileNo"), MessageKeyManager.getMessage("label.officeNo")};
	
	private JLabel lblCustHeader;
	private JLabel lblHome;
	private JLabel lblMobile;
	private JLabel lblOffice;
	
	private ValidateJTextField fieldHome;
	private ValidateJTextField fieldMobile;
	private ValidateJTextField fieldOffice;
	
	private int labelHeight = 20;
	private int fieldHeight = 20;
	private int labelWidth = 200;
	private int fieldWidth = 200;
	private int fieldControlX = 150;
	private int lblControlX = 10; 
	
	public CustomerContactPanel() {
		// TODO Auto-generated constructor stub
		super();
		init();
		
	}
	private JLabel createLabel(String labelContents, int x, int y){
		
		JLabel labelName = new JLabel(labelContents);
		labelName.setVerticalTextPosition(SwingConstants.BOTTOM);
		labelName.setBounds(x, y, labelWidth, labelHeight);
		add(labelName);
		
		return labelName;		
		
	}
	private ValidateJTextField createTextField(String labelName, String text, int x, int y, ValidationRule ... rules){
		
		ValidateJTextField fieldTxtName = new ValidateJTextField(labelName, rules);
		fieldTxtName.setText(text);
		fieldTxtName.setBounds(x, y, fieldWidth, fieldHeight);
		add(fieldTxtName);	
		
		return fieldTxtName;
		
	}
	
	public ValidateJTextField getFieldHome() {
		
		return fieldHome;
		
	}
	public ValidateJTextField getFieldMobile() {
		
		return fieldMobile;
		
	}
	public ValidateJTextField getFieldOffice() {
		
		return fieldOffice;
		
	}
	public void setFieldHome(ValidateJTextField fieldHome) {
		
		this.fieldHome = fieldHome;
		
	}
	public void setFieldMobile(ValidateJTextField fieldMobile) {
		
		this.fieldMobile = fieldMobile;
		
	}
	public void setFieldOffice(ValidateJTextField fieldOffice) {
		
		this.fieldOffice = fieldOffice;
		
	}
	private void init() {
		// TODO Auto-generated method stub
		setLayout(null);
		setPreferredSize(new Dimension(400,300));
		setBounds(0, 400, 400, 300);
		
		lblCustHeader = createLabel("Customer Contact Details:", 10, 5);
		
		int controly = 40;
		
		for(int i = 0; i < labelContent.length; i++){
			
			switch(i){
			case 0: lblHome = createLabel(labelContent[i], lblControlX, controly);
					fieldHome = createTextField(labelContent[i], "", fieldControlX, controly, ValidationRule.LAND_LINE);
					break;
			case 1: lblMobile = createLabel(labelContent[i], lblControlX, controly);
					fieldMobile = createTextField(labelContent[i], "", fieldControlX, controly, ValidationRule.MOBILE);
					break;	
			case 2: lblOffice = createLabel(labelContent[i], lblControlX, controly);
					fieldOffice = createTextField(labelContent[i], "", fieldControlX, controly, ValidationRule.LAND_LINE);
					break;	
			default: break;
			}
			
			controly = controly + 35;
			
		}
			
	}
	
}
